package com.slwish.xty.ui.activity;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.othershe.nicedialog.BaseNiceDialog;
import com.othershe.nicedialog.ShareDialog;
import com.slwish.common.base.ToolbarActivity;
import com.slwish.common.config.Contants;
import com.slwish.common.interf.PerfectClickListener;
import com.slwish.xty.R;
import com.slwish.xty.entity.CreditTourismInfoModel;
import com.slwish.xty.utils.DialogUtils;
import com.slwish.xty.utils.LocalUtils;
import com.slwish.xty.utils.ShareSdkUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 商家详情
 */
public class BusinessDetailsActivity extends ToolbarActivity {
    @BindView(R.id.tv_titls)
    TextView tvTitle;
    @BindView(R.id.tv_location)
    TextView tvLocation;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.ll_add)
    LinearLayout llAdd;
    //    private MainModel.DataBean model;
    private CreditTourismInfoModel model;

    @Override
    protected int getLayoutId() {
        return R.layout.act_business_details;
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        setTitle(R.string.business_detail_title);
        setRightIcon(R.mipmap.share);
        model = (CreditTourismInfoModel) getIntent().getSerializableExtra(Contants.MODEL);
        if (model != null) {
            tvTitle.setText(model.getScenicName());
            tvLocation.setText(model.getAddress());
            tvContent.setText(model.getDescription());
            List<String> imageList = model.getLogo();
            RequestOptions options = new RequestOptions();
            options.placeholder(R.mipmap.zhanweifu_home)
                    .error(R.mipmap.zhanweifu_home)
                    .skipMemoryCache(true);
            RequestManager with = Glide.with(mContext);
            if (imageList != null) {
                for (String imageUrl : imageList) {
                    View inflate = LayoutInflater.from(mContext).inflate(R.layout.item_image, null);
                    ImageView iamgeView = inflate.findViewById(R.id.image);
//                    iamgeView.setLayoutParams(new AutoLinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,400));

                    with.load(imageUrl).apply(options).into(iamgeView);
                    llAdd.addView(inflate);
                }
            }
        }
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        setRightOnClickListener(new PerfectClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
//                ShareSdkUtils.share(mContext);
                DialogUtils.showShareDialog(mContext, new ShareDialog.ShareDialogClickListener() {
                    @Override
                    public void setOnItemClickListener(BaseNiceDialog dialog, View view, int position) {
                        dialog.dismiss();
                        ShareSdkUtils.share(mContext,"信天游", "http://www.baidu.com", "信天游", "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG", position);
                    }
                });
            }
        });
    }

    @OnClick(R.id.ll_location)
    public void setOnClick(View view) {
        LocalUtils.intentToMap(mContext, tvLocation.getText().toString(), model.getLongitude(), model.getLatitude());
    }
}
